using Microsoft.Extensions.Configuration;

namespace SemanticKernelDemo0510.Utils;

public class ProjectEnvironment {
    private static readonly IConfigurationRoot _configuration =
        new ConfigurationBuilder().AddUserSecrets<ProjectEnvironment>().Build();

    internal static string Get(string name) {
        var value = _configuration[name];
        if (!string.IsNullOrEmpty(value)) {
            return value;
        }

        value = Environment.GetEnvironmentVariable(name);
        if (string.IsNullOrEmpty(value)) {
            throw new Exception($"Secret / Env var not set: {name}");
        }

        return value;
    }
}